﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.UI;
using BluePortal.Medias.Core;

namespace BluePortal.QuikStart.UserControls
{
    public partial class MediaComment : System.Web.UI.UserControl
    {
        public Guid MediaID { get; set;}
        private List<Comment> videoComments;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                videoComments = new BCComment().FindByMedia(MediaID, null).ToList();
                rpComment.DataSource = videoComments;
                rpComment.DataBind();
            }
        }

        public int CountVideoComments()
        {
            return videoComments.Count;
        }

        protected void ButtonAddComment_Click(object sender, EventArgs e)
        {
            BCComment bc = new BCComment();
            bc.Create(new Comment()
            { 
                CID = Guid.NewGuid(), 
                Text = taComment.Text,
                LoginName = Page.User.Identity.Name, 
                ID = MediaID, 
                CreationDate = DateTime.Now 
            });

            taComment.Text = string.Empty;
            videoComments = bc.FindByMedia(MediaID, null).ToList();
            rpComment.DataSource = videoComments;
            rpComment.DataBind();
        }
    }
}